//
//  NSAttributedString + Extension.swift
//  weiboZY
//
//  Created by 赵勇 on 16/5/23.
//  Copyright © 2016年 赵勇. All rights reserved.
//

import UIKit


extension NSAttributedString {
    
    class func attributedWithEmoticon(emotion:ZYEmoticon, font:UIFont) -> NSAttributedString {
        
        // 1创建一个UIimage
        let image = UIImage(named: emotion.path!)
        
        // 2 根据UIImage对象创建一个NSTextAttachment
        let attachment = ZYEmoticonTextAttachment()
        
        attachment.emoticon = emotion
        attachment.image = image
        
        // 字体的高度
        let fontHeight = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -3, width: fontHeight, height: fontHeight)
        
        // 3 根据NSTextAttachment创建一个NSAttributedString
        let attar = NSAttributedString(attachment: attachment)
        

        return attar
    }
    
    
    
}







